package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.CashAccountDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashAccount;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Foundation;
import sanrenxing.dayEnd.backRepertoryTotal.service.CashAccountBiz;

import java.util.HashMap;
import java.util.List;

/**
 * 功能：现金业务层实现类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Service
public class CashAccountBizImpl implements CashAccountBiz {
    @Autowired
    private CashAccountDao cashAccountDao;
    /**
     * 添加数据
     *
     * @param cashAccount 现金账户对象
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(CashAccount cashAccount) {
        return cashAccountDao.add(cashAccount);
    }

    /**
     * 删除数据
     * @param caId 现金账户ID
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Override
    public int delete(String caId) {
        //判断是否为批量删除
        if(caId.contains(",")){
            //对现金账户编号按“，”分割
            String[] strs=caId.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除
                cashAccountDao.delete(Integer.parseInt(str));
            }
            //返回1
            return 1;
        }
        return cashAccountDao.delete(Integer.parseInt(caId));
    }

    /**
     * 修改数据
     *
     * @param cashAccount 现金账户对象
     * @return 0:修改失败,1:修改成功
     */
    @Override
    public int update(CashAccount cashAccount) {
        return cashAccountDao.update(cashAccount);
    }

    /**
     * 分页查询所有数据
     * @param cashAccount
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<CashAccount> queryAll(CashAccount cashAccount, int row, int page){
        HashMap<String,Object> map=new HashMap<>();
        map.put("cashAccount",cashAccount);
        map.put("start",page);
        map.put("end",(page+row));
        return cashAccountDao.qureyAll(map);
    }

    /**
     * 统计记录数
     *
     * @param cashAccount
     * @return 记录行数据
     */
    @Override
    public int count(CashAccount cashAccount) {
        return cashAccountDao.count();
    }

    @Override
    public List<Foundation> fs() {
        return cashAccountDao.fs();
    }


}
